<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiQuestionnaireQuestionnaireOptionTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_questionnaire_questionnaire_option';

    /**
     * Run the migrations.
     * @table qii_questionnaire_questionnaire_option
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('option_id')->comment('ID');
            $table->unsignedInteger('questionnaire_id')->default('0')->comment('问题ID');
            $table->string('name', 30)->default('')->comment('答案');
            $table->unsignedInteger('num')->default('0')->comment('选择量');
            $table->unsignedSmallInteger('sortrank')->default('0')->comment('排序');
            $table->unsignedInteger('modified_date')->default('0')->comment('创建时间');

            $table->index(["questionnaire_id"], 'questionnaire_id');

            $table->index(["sortrank"], 'sortrank');

            $table->index(["option_id", "questionnaire_id", "sortrank"], 'option_questionnaire_sortrank_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
